<template>
	<view>
		<view class="page">
			<view class="tab">
				<view class="tabItem" v-for="(item,index) in tab" :key="index" :class="{active:active==index}"
					@click="changeTab(index)">
					<view class="title">{{item}}</view>
					<view class="underLine" :class="{active:active==index}"></view>
				</view>
			</view>
			<view class="content">
				<!-- 未使用 -->
				<view>
					<view class="list" v-if="active==0">
						<view class="coupons" v-for="item in noUseCouponList" :key="item.id">
							<view class="money">¥{{item.cost}}</view>
							<view class="moneyName">{{item.discountName}}</view>
							<view class="moneyTime">{{item.createTime}}前</view>
						</view>
					</view>
				</view>

				<!-- 已使用 -->
				<view class="list" v-if="active==1">
					<view class="coupons" v-for="item in useCouponList" :key="item.id">
						<view class="money">¥{{item.cost}}</view>
						<view class="moneyName">{{item.discountName}}</view>
						<view class="moneyTime">{{item.createTime}}前</view>
					</view>
				</view>
				<!-- 已过期 -->
				<view class="list expired" v-if="active==2">
					<view class="coupons" v-for="item in tmpCouponList" :key="item.id">
						<view class="money">¥{{item.cost}}</view>
						<view class="moneyName">{{item.discountName}}</view>
						<view class="moneyTime">{{item.createTime}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	// pages/payParkingFee/payParkingFee.js
	import context from '../../lib/java110/Java110Context.js';
	const constant = context.constant;

	// import vcDiscount from '@/components/vc-discount/vc-discount.vue'
	// import vcUserAccount from '@/components/vc-user-account/vc-user-account.vue'

	// import {
	// 	addMonth,
	// 	formatDate,
	// 	date2String,
	// 	dateSubOneDay
	// } from '../../lib/java110/utils/DateUtil.js'
	// import {
	// 	getCouponUsers
	// } from '../../api/fee/feeApi.js';

	// import {
	// 	getCommunityId
	// } from '@/api/community/communityApi.js'

	export default {
		data() {
			return {
				couponList: [],
				noUseCouponList: [],
				tmpCouponList: [],
				useCouponList: [],
				userLink: '',
				couponAmount: 0.0,
				imgStaticUrl: this.STATICURL,
				tab: ['未使用', '已使用', '已过期'],
				active: 0, //当前选中项
				// isHas: true,
				// pageShow: false,
				userId: '',
				state: 1
			}
		},
		onLoad: function(options) {
			let that = this
			that.loadOwnerAccount()
		},
		methods: {
			/**
			 * 加载优惠券信息
			 */
			loadOwnerAccount: function() {
				let _that = this;
				let userPhone = uni.getStorageSync("commonUser");
				_that.phone = userPhone.phone
				uni.request({
					url: constant.url.getCoupons,
					header: context.getHeaders(),
					method: "GET",
					data: {
						phone: _that.phone,
					},
					success: function(res) {
						_that.couponList = res.data.result.records;
						// let resNew = _that.couponList.filter((item) => {
						// 	// 参数一是:数组元素
						// 	// 参数二是:数组元素的索引
						// 	// 参数三是：当前的数组
						// 	console.log("item",item.usageStatus)
						// 	return item.usageStatus == 1;
						// });

						// console.log(resNew,"resNew"); // [66,88] 返回值是一个新数组
						for (let i = 0; i < _that.couponList.length; i++) {
							if (_that.couponList[i].usageStatus == 1) {
								_that.noUseCouponList.push(_that.couponList[i])
							} else if (_that.couponList[i].usageStatus == 2) {
								_that.useCouponList.push(_that.couponList[i])
							} else {
								_that.tmpCouponList.push(_that.couponList[i])
							}
						}
						console.log("_that.noUseCouponList", _that.noUseCouponList)
					},
					fail: function(e) {
						wx.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						});
					}
				})
			},


			changeTab(index) {
				console.log(index);
				this.active = index
				// this.loadOwnerAccount()
			}
		}
	}
</script>

<style lang="less">
	.coupons {
		width: 98%;
		height: 150rpx;
		background-color: #3088fb;
		color: #fff;
		display: flex;
		justify-content: space-around;
		align-items: center;
		border-radius: 10rpx;
		margin: 30rpx auto;

		.money {
			font-size: 60rpx;
		}

		.moneyName {}

		.moneyName {}
	}

	.fee-last {
		margin-bottom: 200upx;
	}

	.cu-btn.lgplus {
		padding: 0 20px;
		font-size: 18px;
		height: 100upx;

	}

	.cu-btn.sharp {
		border-radius: 0upx;
	}

	.line-height {
		line-height: 100upx;
	}

	.page {
		.button {
			position: fixed;
			bottom: 80rpx;
			width: 500rpx;
			height: 44px;
			left: 125rpx;
			font-size: 16px;
			background-image: -webkit-linear-gradient(left, #8bbefd, #e0e0e0);
			background-image: linear-gradient(to right, #8bbefd, #e0e0e0);
			box-shadow: 4rpx 4rpx 4rpx #ccc;
			border-radius: 50rpx;
		}

		.tab {
			top: 0;
			position: fixed;
			left: 0;
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-around;
			height: 88rpx;
			background: #fff;
			z-index: 2;
			border-bottom: 1rpx solid #fbfbfb;

			.tabItem {
				font-size: 28rpx;
				line-height: 48rpx;
				color: #999;
				font-weight: 400;

				&.active {
					color: #FA3E3F;
					font-weight: 600;
				}
			}
		}

		.content {
			padding-top: 88rpx;
		}

		// .content {
		// 	padding-top: 88rpx;

		// 	.list {
		// 		background-color: #3088fb;
		// 		margin-bottom: 30rpx;
		// 		.listItem {
		// 			padding: 11rpx 22rpx;
		// 			background: #fff;
		// 			position: relative;
		// 			border-bottom: 1rpx solid #fbfbfb;

		// 			&:last-child {
		// 				border-bottom: none;
		// 			}

		// 			.coupon {
		// 				width: 100%;
		// 				height: 188rpx;
		// 			}

		// 			.box {
		// 				color: #fff;
		// 				position: absolute;
		// 				left: 32rpx;
		// 				top: 32rpx;
		// 				right: 32rpx;
		// 				bottom: 32rpx;
		// 				padding: 42rpx 23rpx 42rpx 31rpx;
		// 				display: flex;
		// 				justify-content: space-around;
		// 				align-items: center;

		// 				.price {
		// 					display: flex;
		// 					justify-content: center;
		// 					align-items: center;
		// 					width: 120rpx;

		// 					.icon {
		// 						font-size: 36rpx;
		// 					}

		// 					.volum {
		// 						font-size: 60rpx;
		// 					}
		// 				}

		// 				.descripe {
		// 					margin-left: 22rpx;
		// 					flex: 1;

		// 					.shop-name {
		// 						background-color: #fff;
		// 						color: #79b2fb;
		// 						border-radius: 50rpx;
		// 						padding: 2rpx 10rpx;
		// 						width: fit-content;
		// 						font-size: 24rpx;
		// 					}

		// 					.text {
		// 						font-size: 24rpx;
		// 						line-height: 33rpx;
		// 						margin-top: 15rpx;
		// 					}

		// 					.expire {
		// 						font-size: 18rpx;
		// 						line-height: 25rpx;
		// 						margin-top: 15rpx;

		// 					}
		// 				}

		// 				.usestate {
		// 					font-size: 24rpx;
		// 					width: 120rpx;
		// 					text-align: center;

		// 					image {
		// 						width: 121rpx;
		// 						height: 121rpx;
		// 					}
		// 				}
		// 			}
		// 		}

		// 	}

		// 	.expired {
		// 		.shop-name {
		// 			color: #adacac !important;
		// 		}
		// 	}
		// }
	}
</style>
